import {editpwd, register, reset, checkUser, editpwd2} from '@/services/user/UserService';
import {setAuthority} from '@/utils/authority';

export default {
    namespace: 'userModel',

    state: {},

    effects: {

        /**
         * 企业注册
         */
        *register({payload, callback}, {call, put}) {
            const response = yield call(register, payload);
            if (callback) callback(response);
        },

        /**
         * 重置密码
         */
        *reset({payload, callback}, {call, put}) {
            const response = yield call(reset, payload);
            if (callback) callback(response);
        },

        /**
         * 修改密码
         */
        *editpwd({payload, callback}, {call, put}) {
            const response = yield call(editpwd, payload);
            if (callback) callback(response);
        },

        /**
         * 检查用户状态
         */
        *checkUser({payload, callback}, {call, put}) {
            const response = yield call(checkUser, payload);
            if (callback) callback(response);
        },

        /**
         * 重置密码
         */
            *editpwd2({payload, callback}, {call, put}) {
            const response = yield call(editpwd2, payload);
            if (callback) callback(response);
        },
    },

    reducers: {
        changeLoginStatus(state, {payload}) {
            setAuthority(payload.currentAuthority);
            return {
                ...state,
                status: payload.status,
                type: payload.type,
            };
        },
    },
}
